package com.pubinfo.passbook.common.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用户报账记录表
 *
 * @TableName t_rule_user_witeoff
 */
@TableName(value = "t_rule_user_witeoff")
@Data
@NoArgsConstructor
@ApiModel(value = "TRuleUserWiteoff", description = "用户报账记录表")
public class TRuleUserWiteoff implements Serializable {
  /**
   *
   */
  @TableId(type = IdType.ASSIGN_UUID, value = "id")
  private String id;
  
  /**
   *
   */
  private String person;
  
  @TableField(fill = FieldFill.INSERT)
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  private Date createTime;
  
  @TableField(fill = FieldFill.INSERT_UPDATE)
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  private Date updateTime;
  /**
   *
   */
  private Integer reimbursementType;
  private Integer status;
  
  private String otherSystemMainId;
  /**
   *
   */
  private BigDecimal sum;
  
  @TableField(exist = false)
  private static final long serialVersionUID = 1L;
  
  public TRuleUserWiteoff(BigDecimal sum, String acct, Integer type) {
    this.sum = sum;
    this.person = acct;
    this.reimbursementType = type;
    this.status = 0;
  }
  
  public static List<TRuleUserWiteoff> toList(MedicineOnJobOrRetireDTO jobDTO, String acct) {
    List<TRuleUserWiteoff> witeoffs = new ArrayList<>();
    BigDecimal hospitalizationSum = jobDTO.getHospitalizationSum();
    BigDecimal outpatientDepartmentSum = jobDTO.getOutpatientDepartmentSum();
    if (hospitalizationSum.compareTo(BigDecimal.ZERO) == 1) {
      TRuleUserWiteoff hospitalization = new TRuleUserWiteoff(jobDTO.getHospitalizationSum(), acct, 330602);
      witeoffs.add(hospitalization);
    }
    if (outpatientDepartmentSum.compareTo(BigDecimal.ZERO) == 1) {
      TRuleUserWiteoff outpatientDepartment = new TRuleUserWiteoff(jobDTO.getOutpatientDepartmentSum(), acct, 330601);
      witeoffs.add(outpatientDepartment);
    }
  
    return witeoffs;
  }
}